package android.apps.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

/**
 * Created by lcy on 2015/12/29.
 */
public class PicDatabaseHelper extends SQLiteOpenHelper {

    //数据库的字段
    public static class PictureColumns implements BaseColumns {
        public static final String IMAGEID = "imageid";
        public static final String PICTURE_PATH = "path";
        public static final String DATETIME = "datetime";
        public static final String PLACE_NAME = "place";
        public static final String MAX_TEMP = "maxtemp";
        public static final String MIN_TEMP = "mintemp";
//        imageid;
//        path;
//        datetime;
//        place;
//        maxtemp;
//        mintemp;
    }

    private Context mContext;

    //数据库名
    private static final String DATABASE_NAME = "info.db";
    //数据库版本号
    private static final int DATABASE_Version = 1;
    //表名
    public static final String TABLE_NAME = "info";


    //创建表
    private String sql = "create table " + TABLE_NAME + " (id integer primary key autoincrement ,path varchar(50),datetime varchar(50),placename varchar(50),age integer )";
    //创建数据库
    public PicDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_Version);
        this.mContext = context;
    }

    //创建表并初始化表
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.e("LCY", "sql==" + sql);
        db.execSQL("CREATE TABLE IF NOT EXISTS info" +
                "(_id INTEGER PRIMARY KEY AUTOINCREMENT,imageid INTEGER, path VARCHAR, datetime VARCHAR, place VARCHAR, maxtemp float,mintemp float)");
        //初始化
    }

    //更新数据库
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = " DROP TABLE IF EXISTS " + TABLE_NAME;
        db.execSQL(sql);
        onCreate(db);
    }
}
